//
//  PersonViewModel.m
//  MVVMTest
//
//  Created by WestWood on 2019/2/20.
//  Copyright © 2019 WestWood. All rights reserved.
//

#import "PersonViewModel.h"

@implementation PersonViewModel

- (instancetype)initWithPerson: (Person *)person {
    self = [super init];
    if (!self) return nil;
    _person = person;
    if (person.salutation.length > 0) {
        _nameText = [NSString stringWithFormat:@"%@ %@ %@", self.person.salutation, self.person.firstName, self.person.lastName];
    } else {
        _nameText = [NSString stringWithFormat:@"%@ %@", self.person.firstName, self.person.lastName];
    }
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"EEEE MMMM d, yyyy"];
    _birthdateText = [dateFormatter stringFromDate:person.birthdate];
    
    return self;
}

- (instancetype)initWithPerson {
    if (self = [super init]) {
        
    }
    return self;
}

- (void)changePersonFirstName {
    [self.person setFirstName:@"This will be a good solution for obeserve mode"];
}

- (void)changePersonLastName: (NSString *)lastName {
    [self.person setLastName:lastName];
    if ([_delegate respondsToSelector:@selector(personHadChange:)]) {
        return [_delegate personHadChange:self.person];
    }
    NSLog(@"Class didn't comfirm the protcol");
}

@end
